package com.acoreful.acf2java.commons.slf4j;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.bridge.SLF4JBridgeHandler;

/**
 * 要实现java.util.Logging桥接到Slf4j，需要执行<br/>
 * <code>
 * SLF4JBridgeHandler.removeHandlersForRootLogger();
 * SLF4JBridgeHandler.install();
 * </code>
 * 
 * @since 0.0.1
 */
public final class Slf4jBridgeHandlerListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        if (SLF4JBridgeHandler.isInstalled()) {
            SLF4JBridgeHandler.uninstall();
        }
    }

}